package com.example.qxfw.qxybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.qxybzz.entity.PageBean;
import com.example.qxfw.qxybzz.entity.dto.StrategyDto;
import com.example.qxfw.qxybzz.mapper.PublishStrategyMapper;
import com.example.qxfw.qxybzz.service.PublishStrategyService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/pubishStrategy")
@RequiredArgsConstructor
public class PublishStrategyController {


    private final PublishStrategyService publishStrategyService;

    /**
     * 分页查询策略
     */
    @GetMapping("/getPageStrategy")
    public SysResult getPageStrategy(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        PageBean pageBean = publishStrategyService.getPageStrategy(page, pageSize);
        return SysResult.success(pageBean);
    }

    /**
     * 删除策略
     */
    @Delete("/deleteStrategy")
    public SysResult deleteStrategy(@RequestParam Integer id) {
        publishStrategyService.deleteStrategy(id);
        return SysResult.success();
    }

    /**
     * 更改策略
     */
    @PostMapping("/updateStrategy")
    public SysResult updateStrategy(@RequestBody StrategyDto strategy) {
        publishStrategyService.updateStrategy(strategy);
        return SysResult.success();
    }


    @PostMapping("/addStrategy")
    public SysResult addStrategy(@RequestBody StrategyDto strategy) {
        publishStrategyService.addStrategy(strategy);
        return SysResult.success();
    }


}
